import {create} from "zustand";
import {SizeType} from "antd/es/config-provider/SizeContext";
import {SIZE, STORAGE} from "@/const";
import {persist} from "zustand/middleware";

interface State {
    logoAndTitleEnable?: boolean,
    menuCollapsed?: boolean,
    breadcrumbEnable?: boolean,
    linkCacheBarEnable?: boolean,
    pageFootEnable?: boolean,
    componentSize?: SizeType,
    language?: string,
}

export interface SystemStoreState extends State {
    setSystem: (state: State) => void,
}

const useSystemStore = create(
    persist<SystemStoreState>(
        set => ({
            // logo和标题
            logoAndTitleEnable: true,
            // 菜单展开/缩起
            menuCollapsed: false,
            // 面包屑
            breadcrumbEnable: true,
            // 导航标签页
            linkCacheBarEnable: true,
            // 页脚
            pageFootEnable: true,
            // 组件大小
            componentSize: SIZE.SMALL,
            // 语言,默认中文
            language: 'zh',
            setSystem(system: State) {
                set(system);
            }
        }),
        {
            name: STORAGE.SYSTEM_KEY
        }
    )
)

export default useSystemStore;